home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / tsbgex / src / video / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  4.6 KB  |  234 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h> 
  4. #include <winb.h>
  5. #include <te.h>
  6. #include <fntb.h>
  7. #include <gui.h>
  8. #include <egb.h>
  9. #include <guidbg.h>
  10. #include <file_dlg.h>
  11. #include "../win.h"
  12.  
  13. int aplid;
  14.  
  15. void main(int argc, char *argv[])
  16. {
  17.     MMICTRL ctrl;
  18.     extern int APL_init();
  19.  
  20.     ctrl.displayPage = SCREENAVAILABLE;
  21.     ctrl.mode = SCREENAVAILABLE;
  22.     ctrl.page0 = SCREENIGNORE;
  23.     ctrl.page1 = SCREENIGNORE;
  24.     ctrl.size = 0;
  25.     ctrl.ptr = NULL;
  26.     ctrl.asize = 0;
  27.     ctrl.aptr = NULL;
  28.     ctrl.white = 15;
  29.     ctrl.black = 8;
  30.     ctrl.gray = 7;
  31.     ctrl.xor = 7;
  32.     
  33.     if (MMI_Open(&ctrl) != NOERR){
  34.         MMI_Close();
  35.         return;
  36.     }
  37.     if (APL_init(argc, argv) != NOERR){
  38.         MMI_Close();
  39.         return;
  40.     }
  41.     MMI_ExecSystem();
  42.     MMI_Close();
  43. }
  44.  
  45. int task_mode = 0x02;
  46.  
  47. APL_init(int argc, char **argv)
  48. {
  49.     extern int timer;
  50.     extern int userFunc();
  51.     extern void videomain();
  52.     extern void active_check();
  53.  
  54.     while (--argc > 0){
  55.         argv++;
  56.         if (strcmp(*argv, "-t") == 0  &&  argc > 1){
  57.             timer = atoi(*++argv);
  58.             argc--;
  59.         } else if (strcmp(*argv, "-m") == 0  &&  argc > 1){
  60.             task_mode = atoi(*++argv);
  61.             argc--;
  62.         }
  63.     }
  64.     aplid = MMI_GetApliId();
  65.     active_check(TRUE);
  66.     MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc);
  67.     MMI_CallMessage(aplid, GM_TITLE, (int)"BGV共存", 0);
  68.     if (task_mode & 0x01)
  69.         MMI_SetIdleTaskFunc(videomain);
  70.     if (task_mode & 0x02)
  71.         MMI_SetIntervalFunc(videomain);
  72.     MMI_CallMessage(aplid, GM_SLEEP, 0, 0);
  73.     return (NOERR);
  74. }
  75.  
  76. int (**winfunc)();
  77.  
  78. connect_server()
  79. {
  80.     int server;
  81.  
  82.     if ((server = MMI_CallMessage(aplid, GM_QUERYID, QM_SAMEAS, (int)SERVER))
  83.                 > NOERR){
  84.         if (MMI_CallMessage(server, GM_EXECUSER, 0, 0) != MAGIC)
  85.             server = NOERR; /* not ready */
  86.         else
  87.             winfunc = (int (**)())MMI_CallMessage(server, GM_EXECUSER, 1, 0);
  88. #ifdef DEBUG
  89.         printf("VIDEO: server = %d, winfunc = 0x%x\n", server, winfunc);
  90. #endif
  91.     } else {
  92. #ifdef DEBUG
  93.         printf("VIDEO: server = %d\n", server);
  94. #endif
  95.         server = NOERR;
  96.     }
  97.     return (server);
  98. }
  99.  
  100. int server = NOERR;
  101. int server_die = FALSE;
  102. int own = FALSE;
  103. int active = FALSE;
  104. int restart = TRUE;
  105. short vramseg;
  106. u_long vramoff;
  107. int pixel, fbwidth, vwidth, vheight, dwidth;
  108. RESOLUTION mode = { 0, 0, 0, 0, 0, 0, };
  109.  
  110. void active_check(int init)
  111. {
  112.     int owner;
  113.     char *title;
  114.     SCRNDATA screen;
  115.     extern int first, count;
  116.     extern int modecmp();
  117.     extern void setup();
  118.     
  119.     if (server == NOERR){
  120.         if ((server = connect_server()) > NOERR){
  121.             init = TRUE;
  122.             restart = TRUE;
  123.             first = TRUE;
  124.             count = 1;
  125.         }
  126.     }
  127.     if (server <= NOERR){
  128.         server = NOERR;
  129.         restart = TRUE;
  130.         count = 1;
  131.         return;
  132.     }
  133.     owner = MMI_CallMessage(aplid, GM_QUERYID, QM_BACKPAGE, 0);
  134.     title = (char *)MMI_CallMessage(owner, GM_TITLE, (int)NULL, 0);
  135. #ifdef DEBUG
  136.     printf("VIDEO: BACKPAGE owner is %s\n", title);
  137. #endif
  138.     MMI_CallMessage(owner, GM_SCRNDATA, FALSE, (int)&screen);
  139.     if (init){
  140.         if (strcmp(title, OWNER) == 0){
  141.             own = TRUE;
  142.             mode = screen.page[1];
  143.             setup(&screen.page[1]);
  144.         } else {
  145.             own = active = FALSE;
  146.         }
  147.         return;
  148.     }
  149.     if (own){
  150.         if (strcmp(title, OWNER) == 0){
  151.             if (modecmp(&mode, &screen.page[1]) != 0){
  152. #ifdef DEBUG
  153.                 printf("VIDEO: mode change\n");
  154. #endif
  155.                 mode = screen.page[1];
  156.                 setup(&screen.page[1]);
  157.             }
  158.         } else {
  159.             own = active = FALSE;
  160.         }
  161.     } else {
  162.         if (strcmp(title, OWNER) == 0){
  163.             own = TRUE;
  164.             setup(&mode);
  165.         }
  166.     }
  167. #ifdef DEBUG
  168.     printf("VIDEO: own=%d, active=%d, restart=%d\n", own, active, restart);
  169. #endif
  170. }
  171.  
  172. void setup(RESOLUTION *page1)
  173. {
  174.     extern int count;
  175.  
  176.     count = 1;
  177.     pixel = page1->pixel;
  178.     fbwidth = page1->byte;
  179.     vwidth = page1->vx;
  180.     dwidth = page1->dx;
  181.     vheight = page1->vy;
  182.     vramseg = page1->segment;
  183.     vramoff = (u_long)page1->offset;
  184.     active = (page1->pixel == 16);
  185. }
  186.  
  187. modecmp(RESOLUTION *a, RESOLUTION *b)
  188. {
  189.     return (memcmp(a, b, sizeof (RESOLUTION) - sizeof (short)));
  190. }
  191.  
  192. userFunc(int apliId, int messId, int info, int data)
  193. {
  194.     int    ret;
  195.     extern void terminate();
  196.  
  197.     ret = ILLEGAL_FUNCTION ;
  198.  
  199.     switch (messId){
  200.         case GM_EXECUSER:    /* server die */
  201. #ifdef DEBUG
  202.             printf("VIDEO: server die\n");
  203. #endif
  204.             server_die = TRUE;
  205.             server = NOERR;
  206.             active = FALSE;
  207.             terminate();
  208.             break;
  209.         case GM_POSTSCRCHG:
  210. #ifdef DEBUG
  211.             printf("VIDEO: POSTSCRCHG\n");
  212. #endif
  213.             if (server_die)
  214.                 server_die = FALSE;
  215.             else
  216.                 active_check(FALSE);
  217.             ret = NOERR;
  218.             break;
  219.         case GM_QUIT:
  220.             terminate();
  221.             MMI_SetHaltFlag(TRUE);
  222.             ret = NOERR;
  223.             break;
  224.         case GM_PURGE:
  225.         case GM_ENVIRONMENT:
  226.         case GM_SHOW:
  227.         case GM_ERASE: 
  228.         case GM_PRESCRCHG: 
  229.             ret = NOERR;
  230.             break;
  231.     }
  232.     return (ret);
  233. }
  234.